package com.lucan.tracking.api;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.PriorityBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * @author qihailong
 * @date 2018/7/27 下午2:17
 * @description TODO
 */
public class ExecutorUtil {
    /**
     * cpu个数
     */
    private static final int CPU_COUNT = Runtime.getRuntime().availableProcessors();


    /**
     * 创建IO线程池
     *
     * @return
     */
    public static ExecutorService crateIOExecutor() {
        final int corePoolSize = Math.max(2, Math.min(CPU_COUNT - 1, 4));
        final int maximumPoolSize = CPU_COUNT * 2 + 1;
        final int keepAliveTime = 30 * 1000;
        return new ThreadPoolExecutor(corePoolSize, maximumPoolSize, keepAliveTime,
                TimeUnit.MILLISECONDS, new PriorityBlockingQueue<Runnable>());
    }
}
